home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / comm / fido / FindSysSrc.lha / FindSysopSrc / FindSysop.c < prev    next >
C/C++ Source or Header  |  1995-08-29  |  5KB  |  214 lines

  1. /***************************************************************************
  2.  * FindSysop.c
  3.  *
  4.  * FindSysop, Copyright ©1995 Lee Kindness.
  5.  *
  6.  */
  7.  
  8. #define PROGNAME "FindSysop"
  9.  
  10. /* All our includes are in this file */
  11. #include "gst.c"
  12.  
  13. #include "FindSysop_rev.h"
  14.  
  15. /* Libraries used, don't auto open them SAS/C :) */
  16. struct Library *NodelistBase = NULL;
  17.  
  18. /* Structure we pass to NLEnumNode, holds useful data */
  19. struct NLEnumData
  20. {
  21.     NodeList ed_NodeList;
  22.     STRPTR   ed_Pattern;
  23.     Addr    *ed_Start;
  24.     BOOL     ed_Full;
  25.     BOOL     ed_Points;
  26.     BOOL     ed_Return;
  27.     ULONG    ed_Matches;
  28. };
  29.  
  30. const char *const nl_keys[NL_ENTRY_MAX] =
  31.     { "Node", "Host", "Hold", "Hub", "Pvt", "Point", "Zone", "Region", "Down" };
  32.  
  33. const char *vtag = VERSTAG;
  34.  
  35.  
  36. /***************************************************************************
  37.  * EnumFunc() -- Called for each node in the nodelist. Print node if it
  38.  * matches 'pattern'
  39.  */
  40. BOOL __saveds __stdargs EnumFunc(Addr *addr, ULONG region, struct NLEnumData *ud)
  41. {
  42.     BOOL ret;
  43.     NodeDesc *nd;
  44.     ret = FALSE;
  45.     
  46.     /* Check if a point, and what to do... */
  47.     if( !ud->ed_Points && addr->Point )
  48.         /* Skip this entry... */
  49.         return( TRUE );
  50.     
  51.     /* Check for ctrl-c */
  52.     if( !CheckSignal(SIGBREAKF_CTRL_C) )
  53.     {
  54.         ret = TRUE;
  55.     
  56.         /* Find that node in nodelist */
  57.         if( nd = NLIndexFind(ud->ed_NodeList, addr, 0) )
  58.         {
  59.             if( (nd->System) &&
  60.                 (MatchPatternNoCase(ud->ed_Pattern, nd->Sysop)) )
  61.               {
  62.                   /* Match! Print the node details */
  63.                   ud->ed_Matches++;
  64.                   if( ud->ed_Full )
  65.                   {
  66.                         Printf("Node %ld:%ld/%ld.%ld, \"%s\" is in %s\n",
  67.                                nd->Node.Zone, nd->Node.Net,
  68.                                nd->Node.Node, nd->Node.Point,
  69.                                nd->System, nd->City);
  70.                         Printf("System is listed as %s\n",
  71.                                (nd->Type < NL_ENTRY_MAX) ? nl_keys[nd->Type] : "unknown type");
  72.                         Printf("Operated by %s\n", nd->Sysop);
  73.                         Printf("Region %ld, Hub %ld\n", nd->Region, nd->Hub);
  74.                         Printf("Baud %ld\n", nd->BaudRate);
  75.                         Printf("Phone %s, ", nd->Phone);
  76.                         if(nd->Cost != -1)
  77.                             Printf("Cost %01ld.%02ld\n", nd->Cost/100, nd->Cost%100);
  78.                         else
  79.                             Printf("Undialable\n");
  80.                         Printf("Flags %s\n\n", nd->Flags);
  81.                     } else
  82.                     {
  83.                         /* Short output mode */
  84.                         Printf("%ld:%ld/%ld.%ld %s, %s, %s, %s\n", nd->Node.Zone, 
  85.                                nd->Node.Net, nd->Node.Node, nd->Node.Point, nd->System, 
  86.                                nd->City, nd->Sysop, nd->Phone);
  87.                     }
  88.                 }
  89.             NLFreeNode(nd);
  90.         }
  91.     } else
  92.         SetIoErr(ERROR_BREAK);
  93.     if( ret )
  94.         ud->ed_Return = TRUE;
  95.     else
  96.         ud->ed_Return = FALSE;
  97.     return ret;
  98. }
  99.  
  100.  
  101. /***************************************************************************
  102.  * main() --
  103.  */
  104. int main(int argc, char **argv)
  105. {
  106.     int ret = RETURN_FAIL;
  107.     
  108.     /* Open libraries */
  109.     if( (NodelistBase = OpenLibrary(TRAPLIST_NAME, TRAPLIST_VER)) &&
  110.         (DOSBase->dl_lib.lib_Version >= 36) ) 
  111.     {
  112.         /* Parse arguments */
  113.         struct RDArgs *rda;
  114.         #define DEF_NODELIST "Nodelist:"
  115.         #define TEMPLATE "PATTERN/M/A,START/K,FULL/S,POINTS/S,BUFSIZE/K/N,NODELIST/K"
  116.         #define OPT_PATTERN 0
  117.         #define OPT_START 1
  118.         #define OPT_FULL 2
  119.         #define OPT_POINTS 3
  120.         #define OPT_BUFSIZE 4
  121.         #define OPT_NODELIST 5
  122.         #define OPT_MAX 6
  123.         STRPTR args[OPT_MAX] = {0, 0, 0, 0, 0, DEF_NODELIST};
  124.  
  125.         if( rda = ReadArgs(TEMPLATE, (LONG *)&args, NULL) ) 
  126.         {
  127.             STRPTR s;
  128.             NodeList nl;
  129.             ULONG bufsize;
  130.             
  131.             if( args[OPT_BUFSIZE] )
  132.                 bufsize = *((ULONG *)args[OPT_BUFSIZE]);
  133.             else
  134.                 bufsize = 0;
  135.             
  136.             /* Open nodelist */
  137.             if( nl = NLOpen(args[OPT_NODELIST], 0) )
  138.             {
  139.                 ret = RETURN_OK;
  140.                 s = *((STRPTR *)args[OPT_PATTERN]);
  141.                 while( (s) && (*s) && !ret ) 
  142.                 {
  143.                     STRPTR pattern;
  144.                     /* Act on the pattern */
  145.                 
  146.                     /* Alloc buffer for tokenized widcard */
  147.                     if( pattern = AllocVec(strlen(s)*3, MEMF_CLEAR) )
  148.                     {
  149.                         /* Parse wildcard */
  150.                         if( ParsePatternNoCase(s, pattern, strlen(s)*3) != -1 )
  151.                         {
  152.                             Addr *start;
  153.                             struct NLEnumData *ud;
  154.                             /* Parse start address */
  155.                             if( args[OPT_START] )
  156.                             {
  157.                                 if( start = AllocVec(sizeof(Addr), MEMF_CLEAR) )
  158.                                 {
  159.                                     if( NLParseAddr(start, args[OPT_START], NULL) )
  160.                                     {
  161.                                         FreeVec(start);
  162.                                         start = NULL;
  163.                                     }
  164.                                 }
  165.                             } else
  166.                                 start = NULL;
  167.                             /* Alloc user data structure */
  168.                             if( ud = AllocVec(sizeof(struct NLEnumData), MEMF_CLEAR) )
  169.                             {    
  170.                                 ud->ed_NodeList = nl;
  171.                                 ud->ed_Pattern = pattern;
  172.                                 ud->ed_Start = start;
  173.                                 ud->ed_Full = (BOOL)args[OPT_FULL];
  174.                                 ud->ed_Points = (BOOL)args[OPT_POINTS];
  175.                                 ud->ed_Matches = 0;
  176.                             
  177.                                 NLEnumNode(nl, bufsize, start, EnumFunc, ud);
  178.                                 if( !ud->ed_Return )
  179.                                 {
  180.                                     LONG error;
  181.                                     error = IoErr();
  182.                                     PrintFault(error, PROGNAME);
  183.                                     ret = RETURN_FAIL;
  184.                                 }
  185.                                 
  186.                                 if( ud->ed_Matches )
  187.                                 {
  188.                                     Printf("\n"
  189.                                            "---\n"
  190.                                            "%ld %s found.\n"
  191.                                            VERS " (" DATE ")\n"
  192.                                            "Copyright (c)Lee Kindness, 2:259/26.20\n",
  193.                                            ud->ed_Matches,
  194.                                            ((ud->ed_Matches == 1) ? "match" : "matches"));
  195.                                 }
  196.                                 FreeVec(ud);
  197.                             }
  198.                         }
  199.                         FreeVec(pattern);
  200.                     }
  201.                 
  202.                     /* Get the next string in the array */
  203.                     s = strchr(s,'\0');
  204.                     s++;
  205.                 }
  206.                 NLClose(nl);
  207.             }
  208.             FreeArgs(rda);
  209.         }
  210.         CloseLibrary(NodelistBase);
  211.     }
  212.     return ret;
  213. }
  214.